	PRO LEER,dir,time,Nproc,a,f,b,u,jj,ww,t,psi
; Read scalar potentials a(x,y), f(x,y), b(x,y) and u(x,y)
; And calculate j(x,y), w(x,y) & psi(x,y) 

leer_input,dir,N,nu,eta,eps,epse,dt,nstep,nstg,nstdat,nstk,nstp

x=2.*!pi*dindgen(N)/N & y=x

aa=dblarr(N,N/Nproc) ; rectangulo de NxNproc
a=dblarr(N,N)
f=a & b=a & u=a 
t=0.d0

; read scalar potential a(x,y)
for j=0,Nproc-1 do begin
file=dir+'a_'+time+'_00'+string(j,format='(i1)')
if j gt 9 then file=dir+'a_'+time+'_0'+string(j,format='(i2)')
openr,1,file,/f77_unformatted ; abre el archivo binario file
readu,1,t,aa
close,1
a(*,j*(N/Nproc):(j+1)*(N/Nproc)-1)=aa
endfor
; read scalar potential f(x,y)
for j=0,Nproc-1 do begin
file=dir+'f_'+time+'_00'+string(j,format='(i1)')
if j gt 9 then file=dir+'f_'+time+'_0'+string(j,format='(i2)')
openr,1,file,/f77_unformatted ; abre el archivo binario file
readu,1,t,aa
close,1
f(*,j*(N/Nproc):(j+1)*(N/Nproc)-1)=aa
endfor
; read scalar potential b(x,y)
for j=0,Nproc-1 do begin
file=dir+'b_'+time+'_00'+string(j,format='(i1)')
if j gt 9 then file=dir+'b_'+time+'_0'+string(j,format='(i2)')
openr,1,file,/f77_unformatted ; abre el archivo binario file
readu,1,t,aa
close,1
b(*,j*(N/Nproc):(j+1)*(N/Nproc)-1)=aa
endfor
; read scalar potential u(x,y)
for j=0,Nproc-1 do begin
file=dir+'u_'+time+'_00'+string(j,format='(i1)')
if j gt 9 then file=dir+'u_'+time+'_0'+string(j,format='(i2)')
openr,1,file,/f77_unformatted ; abre el archivo binario file
readu,1,t,aa
close,1
u(*,j*(N/Nproc):(j+1)*(N/Nproc)-1)=aa
endfor
; Calculate j(x,y), w(x,y) y psi(x,y)
jj = dblarr(N,N)
ww = dblarr(N,N)
psi = dblarr(N,N)

k2 = dist(N)^2
p = where(k2 lt 1e-6)
k2(p) = 1e-6

ak = fft(a,-1)
fk = fft(f,-1)
bk = fft(b,-1)

jj = float(fft(k2*ak,1))
ww = float(fft(k2*fk,1))
psi = float(fft((1/k2)*bk,1))
end
